using System;
using System.Diagnostics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using POCGame.Screens;
using Rocuna.GameEngine;
using Rocuna.GameEngine.Extension.WP7.Input;
using Rocuna.GameEngine.Extension.WP7.Input.Constants;
using Rocuna.GameEngine.Graphics;
using Rocuna.GameEngine.Graphics.Cameras;

namespace POCGame
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : RocunaGame
    {
        public Game1()
        {
            Content.RootDirectory = "Content";

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            var bootstrapper = new Bootstrapper();
            bootstrapper.Run(this);
            base.Initialize();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {

            base.Draw(gameTime);
        }

        protected override void LoadGameContent(GameTime gameTime)
        {
            base.LoadGameContent(gameTime);
            InputManager.RegisterDevice(new PhoneGestureDevice(this));
            InputManager.ActivateDevice(PhoneDevices.PhoneGestureDevice);
            var mainMenu = new MainMenu(this);
            ScreenManager.RegisterScreen("MainMenu", mainMenu);
            ScreenManager.ActivateScreen("MainMenu");
            var level1 = new Level1(this);
            ScreenManager.RegisterScreen("Level1", level1);
            var launcherLevel1 = new LoadingScreen(this);
            ScreenManager.RegisterScreen("Level1Launcher", launcherLevel1);
            GraphicManager.RegisterCamera(new TargetCamera(new Vector3(50, 50, 50), Vector3.Zero, this));
            GraphicManager.RegisterCamera(new FreeCamera(new Vector3(300, 300, 300), -11.81321f, -0.6393386f, this));
            GraphicManager.ActivateCamera(CamerasNames.FreeCamera);
        }
    }
}
